package com.aiju.support.aop;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: 佐为
 * @date: 2017-03-21 16:22
 * @version: V1.0
 * @Description: 拦截器
 */
public abstract class AInterceptor implements IInterceptor {

    public static final String TAG = "HttpLog";

    protected List<String> methods = new ArrayList();

    public AInterceptor() {
        this.addMetodName();
    }

    @Override
    public Object before(Object proxied, Method method, Object[] args) {
        return this.isAdd(method.getName()) ? this.interceptor(proxied, method, args) : AInterceptorHandler.DEFAULT;
    }

    @Override
    public Object after(Object proxied, Method method, Object[] args, Object methodReturn) {
        return AInterceptorHandler.DEFAULT;
    }

    private boolean isAdd(String methodName) {
        return methods.contains(methodName);
    }

    protected abstract void addMetodName();

    protected abstract Object interceptor(Object proxied, Method method, Object[] args);
}

